package com.interview01;

/**
 * Copyright (C), 2018-2020
 * FileName: PresidentLazy
 * Author:   kongfanyu
 * Date:     2020/12/4 16:05
 */
public class PresidentLazy {

    private static PresidentLazy presidentLazy;

    private PresidentLazy(){
        System.out.println("创建川建国对象...");
    }

    //问题：每次一个线程执行都用获取锁对象，其实没有必要，第一次创建对象之后 presidentLazy 不为null
    public static  PresidentLazy getInstance(){
        if(presidentLazy == null) {
            synchronized (PresidentLazy.class) {
                if (presidentLazy == null) {
                    presidentLazy = new PresidentLazy();
                }
            }
        }
        return  presidentLazy;
    }
}
